package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：毕龙
 * Date: 2023/7/27 16:57
 */
@WebServlet("/cookie")
public class ServletCookie1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建cookie对象
        Cookie cookie = new Cookie("name", "李勇超");
        Cookie cookie1 = new Cookie("url", "cookie");
        cookie1.setMaxAge(0);
        resp.addCookie(cookie1);


        Cookie[] cookies = req.getCookies();
        for (Cookie cookie2 : cookies) {
            System.out.println(cookie2.getName()+"="+cookie2.getValue());
        }


    }
}
